/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springblade;

import com.google.common.collect.ImmutableMap;
import org.mitre.dsmiley.httpproxy.ProxyServlet;
import org.springblade.common.constant.LauncherConstant;
import org.springblade.core.launch.BladeApplication;
import org.springblade.modules.huikecloud.controller.GrafanaProxyServlet;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * 启动器
 *
 * @author Chill
 */
@EnableScheduling
@SpringBootApplication
public class Application {

	public static void main(String[] args) {
		BladeApplication.run(LauncherConstant.APPLICATION_NAME, Application.class, args);
	}

	@Bean
	public RestTemplate restTemplate() {
		return new RestTemplate(new OkHttp3ClientHttpRequestFactory());
	}



	@Bean
	public ServletRegistrationBean<GrafanaProxyServlet> grafanaServletRegistration() {
		ServletRegistrationBean<GrafanaProxyServlet> registrationBean = new ServletRegistrationBean<>(new GrafanaProxyServlet(), "/grafana/*");
		//设置网址以及参数
		Map<String, String> params = ImmutableMap.of("targetUri", "http://127.0.0.1:13000/grafana");
		registrationBean.setInitParameters(params);
		return registrationBean;
	}

	@Bean
	public ServletRegistrationBean chfsServletRegistration() {
		ServletRegistrationBean registrationBean = new ServletRegistrationBean(new ProxyServlet(),"chfs/*");
		//设置网址以及参数
		Map<String, String> params = ImmutableMap.of("targetUri", "http://10.0.49.23:8888/chfs");
		registrationBean.setInitParameters(params);
		return registrationBean;
	}
//
//	@Bean
//	public SpringContextUtil getContext(){
//		return new SpringContextUtil();
//	}
}

